package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.web.admin.mapper.ApartmentFacilityMapper;
import com.atguigu.lease.web.admin.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.admin.mapper.FacilityInfoMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.ApartmentFacility;
import com.atguigu.lease.web.admin.service.ApartmentFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author liubo
* @description 针对表【apartment_facility(公寓&配套关联表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class ApartmentFacilityServiceImpl extends ServiceImpl<ApartmentFacilityMapper, ApartmentFacility>
    implements ApartmentFacilityService{
    @Autowired
    private ApartmentInfoMapper apartmentMapper;
    @Autowired
    private FacilityInfoMapper facilityMapper;
    @Override
    public List<FacilityInfo> getFacilityInfoById(Long id) {
        List<ApartmentFacility> list = super.list(new LambdaQueryWrapper<ApartmentFacility>().eq(ApartmentFacility::getApartmentId, id));//获取符合信息的表
        if (list.isEmpty()) { // 关键判空逻辑
            return Collections.emptyList();
        }

        List<FacilityInfo> facilityInfos = facilityMapper.selectList(new LambdaQueryWrapper<FacilityInfo>().in(FacilityInfo::getId, list.stream().map(ApartmentFacility::getFacilityId).collect(Collectors.toList())));

        return facilityInfos;
    }
//或者在中间表查询,拿着查询结果去另外表里边对应然后输出为list

}




